package com.shj.em.biz.prod.service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.shj.em.biz.prod.entity.OrderCnc;
import com.shj.em.biz.prod.mapper.OrderCncMapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import com.baomidou.mybatisplus.plugins.Page;

import java.util.List;
import java.util.Map;

import com.shj.em.biz.hr.entity.Emp;
import com.shj.em.biz.hr.mapper.EmpMapper;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;


/**
 * 订单程序段表 服务实现类
 *
 * @author Shen Huang Jian
 * @since 2018-11-19
 */
@Service
@Transactional
public class OrderCncServiceImpl extends ServiceImpl<OrderCncMapper, OrderCnc> implements OrderCncService {

    @Autowired
    OrderCncMapper ordercncMapper;

    @Autowired
    EmpMapper empMapper;

    public Page<OrderCnc> queryOrderCncPage(Map<String, Object> params){
        int offset = (Integer)params.get("offset");
        int pageSize = (Integer)params.get("limit");
        int pageNo = offset / pageSize + 1;
        Page<OrderCnc> page = new Page(pageNo, pageSize);
        List<OrderCnc> list = ordercncMapper.queryOrderCncPage(page, params);
        return page.setRecords(list);
    }

    public List<OrderCnc> findOrderCncByOrderId(Long orderId){
        Wrapper<OrderCnc> wrapper = new EntityWrapper<>();
        wrapper.eq("order_id", orderId);
        List<OrderCnc> list = ordercncMapper.selectList(wrapper);
        if(list != null && list.size() > 0){
            for(OrderCnc cnc : list){
                if(cnc.getEmpId() != null){
                    Emp emp  = empMapper.selectById(cnc.getEmpId());
                    cnc.setEmpName(emp.getEmpName());
                }
            }
        }
        return list;
    }

    public Long insertCnc(OrderCnc orderCnc){
        ordercncMapper.insert(orderCnc);
        return orderCnc.getId();
    }

//    public List<OrderCnc> findCncInfoByDate(Date date){
//
//    }
}
